﻿using MediatR;
using T.Materials.Domain.Model;
using T.Materials.Read.API.ApplicationRead.Command.MaterialStoreCommand;
using T.Materials.Repository.MaterialsInterface;
using static T.Materials.Domain.Enum.Enums;

namespace T.Materials.Read.API.ApplicationRead.CommandHandler.MaterialStoreCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class MaterialStoreNameCommandHandler : IRequestHandler<MaterialStoreNameCommand, List<MaterialStore>>
    {
        /// <summary>
        /// 物资与入库仓储接口
        /// </summary>
        protected readonly IMaterialStoreRepository materialStoreRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="materialStoreRepository">物资与入库仓储接口</param>
        public MaterialStoreNameCommandHandler(IMaterialStoreRepository materialStoreRepository)
        {
            this.materialStoreRepository = materialStoreRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<List<MaterialStore>> Handle(MaterialStoreNameCommand request, CancellationToken cancellationToken)
        {
            var list = (from a in await materialStoreRepository.GetAllAsync()
                        where !a.IsDeleted && a.ApprovalStatus== ApprovalStatus.已通过
                        select new MaterialStore
                        {
                            MaterialStoreId = a.MaterialStoreId,
                            NameOfGoods = a.NameOfGoods,
                        }).ToList();
            return list;
        }
    }
}
